package com.wangzaiplus.test.juc.thread;

/**
 * @ClassName SynDemo1
 * @Description: TODO
 * @Author wgc
 * @Date 2020/06/28 18:05
 * @Version V1.0
 **/
public class SynDemo1 {
    static int num=0;
    public static synchronized void m1(){
        for (int i = 0; i <10000; i++) {
            num++;
        }
    }

    public static class T1 extends  Thread{
        @Override
        public void run() {
            SynDemo1.m1();
        }
    }
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i <100 ; i++) {
            T1 t1 = new T1();
            T1 t2 = new T1();
            T1 t3 = new T1();
            t1.start();
            t2.start();
            t3.start();
            //等待3个线程结束打印num
            t1.join();
            t2.join();
            t3.join();
        }
        System.out.println(SynDemo1.num);

    }
}
